package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.anno.AutoFill;
import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.*;

import java.util.List;


public interface DishMapper {

    @Select("select count(1) from dish where category_id = #{id}")
    int checkCountByCategoryId(Long id);

    /**
     * 新增菜品
     * @param dish
     */
    @Options(useGeneratedKeys = true,  keyProperty = "id")
    @AutoFill(value = OperationType.INSERT)
    @Insert("insert into dish  values (null ,#{name}, #{categoryId}, #{price}, #{image},#{description},#{status}, #{createTime}, #{updateTime}, #{createUser}, #{updateUser} )")
    void insert(Dish dish);

    /**
     * 菜品分页查询,需要连表进行查询
     * @param dto
     * @return
     */
    Page<Dish> page(DishPageQueryDTO dto);

    /**
     * 根据id查询菜品,也需要连表查询
     * @param id
     * @return
     */
    DishDTO getById(Long id);

    /**
     * 修改菜品
     * @param
     */
    @AutoFill(value = OperationType.UPDATE) // 自动填充修改的字段
    void update(Dish dish);

    /**
     * 批量删除菜品
     * @param idList
     */
    void deleteBatch(List<String> idList);

    /**
     * 根据种类id查询菜品
     * @param categoryId
     * @return
     */
    @Select("select * from dish where category_id = #{categoryId}")
    List<Dish> getByCategoryId(Integer categoryId);

    /**
     * 根据dish查询
     * @param dish
     * @return
     */
    List<Dish> ListBy(Dish dish);
}
